{% extends 'base.html' %}

{% block title %}测试报告列表{% endblock %}
{% block header %}测试报告列表{% endblock %}
{% block content %}


    <div class="card">
        <div class="card-body">
         <form method="get" class="d-flex">
                <div class="col-md-4">
                    <select name="project" id="project" class="form-select">
                        <option value="">所有项目</option>
                        {% for project in projects %}
                            <option value="{{ project.id }}"
                                    {% if selected_project == project.id|stringformat:"s" %}selected{% endif %}>{{ project.name }}</option>
                        {% endfor %}
                    </select>
                </div>
                <div class="col-md-4">
                    <input type="text" name="q" id="q" class="form-control" placeholder="搜索报告名称或描述"
                           value="{{ search_query }}">
                </div>
                <div class="col-md-2 d-flex align-items-end">
                    <button type="submit" class="btn btn-primary ">
                        <i class="bi bi-search"></i>
                    </button>
                </div>
            </form>
            {% if page_obj %}
                <div class="table-responsive">
                    <table class="table table-hover">
                        <thead>
                        <tr>
                            <th>名称</th>
                            <th>描述</th>
                            <th>项目</th>
                            <th>报告类型</th>
                            <th>格式</th>
                            <th>生成时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {% for report in page_obj %}
                            <tr>
                                <td>
                                    <a href="{% url 'test_report_detail' report.id %}">{{ report.name }}</a>
                                </td>
                                <td>{{ report.description }}</td>
                                <td>{{ report.project.name }}</td>
                                <td>
                                    {% if report.report_type == 'test_run' %}
                                        单个测试用例
                                    {% elif report.report_type == 'test_suite_run' %}
                                        测试套件
                                    {% else %}
                                        自定义
                                    {% endif %}
                                </td>
                                <td>{{ report.report_format|upper }}</td>
                                <td>{{ report.created_at|date:"Y-m-d H:i" }}</td>
                                <td>
                                    <div class="btn-group">
                                        <a href="{% url 'test_report_detail' report.id %}"
                                           class="btn btn-sm btn-primary">查看</a>
                                        <a href="{% url 'test_report_delete' report.id %}"
                                           class="btn btn-sm btn-danger">删除</a>
                                    </div>
                                </td>
                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                </div>

                {% include 'pagination.html' with page_obj=page_obj %}

            {% else %}
                <div class="alert alert-info">
                    没有找到测试报告。
                </div>
            {% endif %}
        </div>
    </div>

{% endblock %}
